<?xml version="1.0" encoding="UTF-8" ?>

<!DOCTYPE sqlMap      
    PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN"      
    "http://ibatis.apache.org/dtd/sql-map-2.dtd">

<sqlMap namespace="${base.className}">

	<typeAlias alias="${base.className}" type="${base.modelPackageName}.${base.className}" />

	<resultMap id="${base.className}Result" class="${base.className}">
		<#list bodys as o>
		<result property="${o.propertyName}" column="${o.colName}" jdbcType="${o.colType}"/>
		</#list>
	</resultMap>

	<!-- 返回List，含参数 -->
	<select id="selectListByArgs" parameterClass="java.util.Map" resultMap="${base.className}Result">
		SELECT * FROM TD_ROLE
	</select>
	
	<!-- 返回List，无参数 -->
	<select id="selectAllNotArgs" resultMap="${base.className}Result">
		SELECT * FROM ${base.tableName}
	</select>
	
	<!-- 返回obj，无参数 -->
	<select id="selectByArgs" parameterClass="java.util.Map" resultMap="${base.className}Result">
		SELECT * FROM ${base.tableName}
	</select>
	
	<sql id="selectAll">
		SELECT * FROM ${base.tableName} 
	</sql>
 
	<select id="pageByArgs" parameterClass="com.baby.core.Page" resultMap="${base.className}Result">
		SELECT * FROM (SELECT a.*, ROWNUM rownum_ FROM(
			<include refid="selectAll" />
		<![CDATA[
		)a WHERE ROWNUM <= #endIndex# ) WHERE rownum_ >= #beginIndex#
		]]>
	</select>
	
	<select id="pageCountByArgs" parameterClass="com.baby.core.Page" resultClass="Long">
		SELECT COUNT(*) FROM (
			<include refid="selectAll" />
		)
	</select>
	
	<#if base.pkParaClassName!="empty">
	<select id="selectByPK" resultMap="${base.className}Result" parameterClass="${base.pkParaClassName}" >
	    select <#list bodys as o>${o.colName}<#if o_has_next>, </#if></#list>
	      from ${base.tableName}
	    where 1 = 1
		<#list pkBodys as o>
		  and ${o.colName} = #${o.propertyName}#
		</#list>
    </select>

    <delete id="deleteByPK" parameterClass="${base.pkParaClassName}" >
	    delete from ${base.tableName}
	    where 1=1 
		<#list pkBodys as o>
		  and ${o.colName} = #${o.propertyName}#
		</#list>
    </delete>
    
    <update id="updateSelectiveByPK" parameterClass="${base.className}">
    	update ${base.tableName}
    <dynamic prepend="set">
    <#list notPkBodys as o>
      <isNotNull prepend="," property="${o.propertyName}">
        ${o.colName} = #${o.propertyName}#
      </isNotNull>
    </#list>
    </dynamic>
     	where 1=1
    <#list pkBodys as o>
      	  and ${o.colName} = #${o.propertyName}#
    </#list>
    </update>
    
    <update id="updateByPK" parameterClass="${base.className}">
    	update ${base.tableName} set
    <#list bodys as o>
		  ${o.colName} = #${o.propertyName}#<#if o_has_next>, </#if>
    </#list>
		where 1=1
	<#list pkBodys as o>
		  and ${o.colName} = #${o.propertyName}#
    </#list>
    </update>
    
    </#if>
	
	<insert id="insert" parameterClass="${base.className}" >
	    insert into ${base.tableName}
	    (<#list bodys as o>${o.colName}<#if o_has_next>, </#if></#list>)
	    values 
	    (<#list bodys as o>#${o.propertyName}#<#if o_has_next>, </#if></#list>)
    </insert>
    
    <insert id="insertSelective" parameterClass="${base.className}" >
	    insert into ${base.tableName}
	    <dynamic prepend="(" >
	      <#list bodys as o>
	      <isNotNull prepend="," property="${o.propertyName}" >
	        ${o.colName}
	      </isNotNull>
	      </#list>
	      )
	    </dynamic>
	    values
	    <dynamic prepend="(" >
	      <#list bodys as o>
	      <isNotNull prepend="," property="${o.propertyName}" >
	        #${o.propertyName}#
	      </isNotNull>
	      </#list>
	      )
	    </dynamic>
  	</insert>



</sqlMap>